package charts;
import hxjson2.JSON;

class Factory
{
	var attach_right:Array<Dynamic>;

	public static function make_chart( json:Dynamic ) : ObjectCollection
	{
		var collection = new ObjectCollection();
		
		// multiple bar charts all have the same X values, so
		// they are grouped around each X value, this tells
		// ScreenCoords how to group them:
		var bar_group:Int = 0;
		var name:String = '';
		var c:Int=1;
		
		var elements:Array<Dynamic> = cast( json['elements'], Array<Dynamic>);
		
		for( i in 0...elements.length)
		{
			// trace( elements[i]['type'] );	
			switch( elements[i]['type'] ) {
				case 'bar' :
					collection.add( new Bar( elements[i], bar_group ) );
					bar_group++;
					
				
				case 'line':
					collection.add( new Line( elements[i] ) );
					
					
				case 'area':
					collection.add( new Area( elements[i] ) );
					
					
				case 'pie':
					collection.add( new Pie( elements[i] ) );
					
					
				case 'hbar':
					collection.add( new HBar( elements[i] ) );
					bar_group++;
					
					
				case 'bar_stack':
					collection.add( new BarStack( elements[i], c, bar_group ) );
					bar_group++;
					
					
				case 'scatter':
					collection.add( new Scatter( elements[i] ) );
					
					
				case 'scatter_line':
					collection.add( new ScatterLine( elements[i] ) );
					
					
				case 'bar_sketch':
					collection.add( new BarSketch( elements[i], bar_group ) );
					bar_group++;
					
					
				case 'bar_glass':
					collection.add( new BarGlass( elements[i], bar_group ) );
					bar_group++;
					
					
				case 'bar_cylinder':
					collection.add( new BarCylinder( elements[i], bar_group ) );
					bar_group++;
					

				case 'bar_cylinder_outline':
					collection.add( new BarCylinderOutline( elements[i], bar_group ) );
					bar_group++;
					

				case 'bar_dome':
					collection.add( new BarDome( elements[i], bar_group ) );
					bar_group++;
					

				case 'bar_round':
					collection.add( new BarRound( elements[i], bar_group ) );
					bar_group++;
					

				case 'bar_round_glass':
					collection.add( new BarRoundGlass( elements[i], bar_group ) );
					bar_group++;
					

				case 'bar_round3d':
					collection.add( new BarRound3D( elements[i], bar_group ) );
					bar_group++;
					
				
				case 'bar_fade':
					collection.add( new BarFade( elements[i], bar_group ) );
					bar_group++;
					
				
				case 'bar_3d':
					collection.add( new Bar3D( elements[i], bar_group ) );
					bar_group++;
					
				
				case 'bar_filled':
					collection.add( new BarOutline( elements[i], bar_group ) );
					bar_group++;
					
				
				case 'bar_plastic':
					collection.add( new BarPlastic( elements[i], bar_group ) );
					bar_group++;
					
				
				case 'bar_plastic_flat':
					collection.add( new BarPlasticFlat( elements[i], bar_group ) );
					bar_group++;
					
					
				case 'shape':
					collection.add( new Shape( elements[i] ) );
					
				
				case 'candle':
					collection.add( new Candle( elements[i], bar_group ) );
					bar_group++;
					
	
			}
		}
	
		var y2:Bool = false;
		var y2lines:Array<Dynamic>;
		
		//
		// some data sets are attached to the right
		// Y axis (and min max)
		//
		//this.attach_right = new Array();
						
		//if( lv.show_y2 != undefined )
		//	if( lv.show_y2 != 'false' )
		//		if( lv.y2_lines != undefined )
		//		{
		//			this.attach_right = lv.y2_lines.split(",");
		//		}
		
		collection.groups = bar_group;
		return collection;
	}
}
